pub mod collect;
pub mod content;
pub mod fbf;
pub mod rdb;
pub mod tbase;

pub use collect::Collect;
pub use content::Content;
pub use fbf::Fbf;
pub use rdb::Rdb;
pub use tbase::KeyNode;

use super::{
    err, err_value, json, ok, throw_err, Base, CSend, Client, ECode, Lock, MapSv, RNull, Resp,
    SStr, SvCache, VBase, VMap, Value, VecS, VecSv, VecV,
};
use base::file::JsonFile;

pub fn init_dir() {
    let p = get_cfg_root();
    let _ = JsonFile::make_dir(&p);

    let p = get_backup_root();
    let _ = JsonFile::make_dir(&p);

    let p = get_restore_root();
    let _ = JsonFile::make_dir(&p);
}

pub fn get_cfg_root() -> String {
    if cfg!(windows) {
        "./cfg".to_string()
    } else {
        "/files/cfg".to_string()
    }
}

pub fn get_backup_root() -> String {
    if cfg!(windows) {
        "./backup".to_string()
    } else {
        "/files/backup".to_string()
    }
}

pub fn get_root() -> String {
    if cfg!(windows) {
        "./db".to_string()
    } else {
        "/files/db".to_string()
    }
}

pub fn get_restore_root() -> String {
    if cfg!(windows) {
        "./restore".to_string()
    } else {
        "/files/restore".to_string()
    }
}

pub fn get_cfg_file(line: &str, sub: &str, k: &str) -> String {
    let path = get_cfg_root();

    let mut p = path.to_string();
    if !line.is_empty() {
        p = format!("{p}/{line}");
    }

    if !sub.is_empty() {
        p = format!("{p}/{sub}");
    }

    let _ = JsonFile::make_dir(&p);

    format!("{p}/{k}.json")
}
